package com.winai.launcher.view.guide;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;

import com.ks.projectbasictools.utils.DisplayUtils;
import com.winai.launcher.R;
import com.winai.launcher.base.BaseActivity;
import com.winai.launcher.constant.VideoConstant;
import com.winai.launcher.manager.DeviceInfoManager;
import com.winai.launcher.utils.BaseUtils;
import com.winai.launcher.utils.QRCodeUtil;
import com.winai.launcher.utils.cache.PreloadManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：康少
 * 时间：2020/2/28
 * 说明：激活设备——已弃用
 */
public class ActivateDeviceActivity extends BaseActivity {
    private Context mContext = this;
    private final String activateUrl = "康少是个大帅哥康少是个大帅哥康少是个大帅哥康少是个大帅哥康少是个大帅哥康少是个大帅哥康少是个大帅哥";

    @BindView(R.id.iv_activate)
    ImageView ivActivate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activate_device);
        ButterKnife.bind(this);
        initView();
        /*downloadVideo();*/
        //开始预加载
        PreloadManager.getInstance(mContext).addPreloadTask(VideoConstant.URL_AD, 0);
    }

    @SuppressLint("ClickableViewAccessibility")
    private void initView() {
        Bitmap logoBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher);
        Bitmap qrCodeBitmap = QRCodeUtil.createQRCodeBitmap(activateUrl, DisplayUtils.dp2px(mContext, 311)
                , DisplayUtils.dp2px(mContext, 311)
                , "UTF-8", "L", "2", Color.BLACK, Color.WHITE, logoBitmap
                , 0.2f, null);
        ivActivate.setImageBitmap(qrCodeBitmap);
    }

    @OnClick(R.id.tv_goto)
    public void onViewClicked() {
        //进入引导视频
        startActivity(new Intent(mContext, GuideVideoActivity.class));
        DeviceInfoManager.getInstance(mContext).firstBindAndActivate(
                true
                , BaseUtils.timeStamp2Date(BaseUtils.getInitTime(), "")
                , true
                , ""
        );
    }
}
